local ELEMENT = {}
dhlite.PrepareElement( ELEMENT, "curl" )

ELEMENT.Name         = "Curl"
ELEMENT.DefaultOn    = true

ELEMENT.Description = ""

ELEMENT.HOOK = {}

function ELEMENT:Load()
	self.myMaterial = Material( "proxi/beacon_flare_add" )
	self.color = Color( 192, 128, 255, 255 )
	
	self.NUM_SEGS = 100
	
	self.SPINS = 5
	self.RADIUS = 32
	self.HEIGHT = 128
	
	self.landmarkOnce = nil
	self.curl = {}
	
end

function ELEMENT:Calculate( )
	if not self.landmarkOnce then
		self.landmarkOnce = LocalPlayer():GetPos() + Vector( 256, 0, 0 )
		
		for i = 1, self.NUM_SEGS do
			local fRel = (i - 1) / (self.NUM_SEGS - 1)
			local fPosix = math.sin( fRel * math.pi )
			local fCurix = math.cos( fRel * math.pi )
			
			local curlX = math.cos( fRel * math.pi * self.SPINS ) * self.RADIUS * fPosix
			local curlY = math.sin( fRel * math.pi * self.SPINS ) * self.RADIUS * fPosix
			local curlZ = self.HEIGHT * fPosix
			self.curl[i] = self.landmarkOnce * 1 + Vector( curlX, curlY, curlZ )
			
		end
		
	end
	
end

function ELEMENT.HOOK:PostDrawTranslucentRenderables( )
	self:Calculate( )
	
	local time = CurTime() / 2
	render.SetMaterial( self.myMaterial )
	
	render.StartBeam( self.NUM_SEGS )
	local fRel = 0
	for i = 1, self.NUM_SEGS do
		fRel = (i - 1) / (self.NUM_SEGS - 1)
		render.AddBeam( self.curl[i], math.sin(fRel * math.pi) * 8, (fRel + time) , self.color )
		
	end
	render.EndBeam( )
	
end


dhlite.RegisterElement( ELEMENT )
